package com.langangkj.tools.redis.handler.impl;

import com.langangkj.tools.redis.handler.AbstractRedisKeyMetaHandler;
import com.langangkj.tools.redis.handler.meta.RedisKeyMeta;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author ZhouChuGang
 * @version 1.0
 * @project redis-sync-tools
 * @date 2020/4/26 9:48
 * @Description redis 字符串类型处理者
 */
@Slf4j
@Component
public class RedisStringKeyMetaHandler extends AbstractRedisKeyMetaHandler {

    @Autowired
    @Qualifier("srcRedisTemplate")
    private RedisTemplate<byte[], byte[]> srcRedisTemplate;


    @Autowired
    @Qualifier("desRedisTemplate")
    private RedisTemplate<byte[], byte[]> descRedisTemplate;

    @Override
    protected DataType getSupportDataType() {
        return DataType.STRING;
    }

    @Override
    public void handler(RedisKeyMeta redisKeyMeta) {
        byte[] result = srcRedisTemplate.opsForValue().get(redisKeyMeta.getKeyName());
        log.info("string 开始处理-------------------{} --> {}", redisKeyMeta, result);
        descRedisTemplate.opsForValue().set((byte[]) redisKeyMeta.getKeyName(), result);
    }
}
